#!/bin/sh

if [ -z "$1" ]; then
   echo "ERROR: no arguments, expect [spring.profiles.active]：dev, test, prod"
    exit 0
fi
PROFILE=$1
if [ $PROFILE != "dev" -a $PROFILE != "test" -a $PROFILE != "prod" ] ;then
   echo "ERROR: you input [spring.profiles.active] is $PROFILE, but expect：dev, test, prod"
   exit 0
fi
echo "[spring.profiles.active]: $PROFILE"


## 源码拉取
git pull

## 路径检测
if [ ! -d ./deploy ]; then
 sudo mkdir -p deploy/log

fi

## 本地库路径
if [ ! -d /data/urule/repo ]; then
    sudo mkdir -p /data/urule/repo
fi

## 打包
mvn -Dmaven.test.skip=true clean compile package -f pom.xml -P $PROFILE
mv target/urule-springboot-dgstar-0.0.1-SNAPSHOT.jar deploy

## 服务停止
echo '服务即将停止..'
kill -9 `jps -l | grep urule-springboot-dgstar-0.0.1-SNAPSHOT | awk '{print $1}'`
sleep 3

## 服务启动
echo '服务即将启动..'
cd deploy
nohup java -server -Xmx512m -Xms512m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGCDetails -XX:+PrintGC -XX:+HeapDumpOnOutOfMemoryError -Xloggc:log/gc.log -XX:HeapDumpPath=dump  -jar urule-springboot-dgstar-0.0.1-SNAPSHOT.jar > log/urule-springboot-dgstar.log 2>&1 &
tail -fn 400 log/urule-springboot-dgstar.log

